#include "label.h"

Label::Label(QWidget *parent) :QLabel(parent)
{
    //设置默认鼠标追踪
    this->setMouseTracking(true);
}
Label::~Label()
{

}
void Label::mousePressEvent(QMouseEvent* qme)
{
    Qt::MouseButton mouseButton =  qme->button();
    if (mouseButton == Qt::LeftButton) {
        qDebug()<<"左键";
    }
    else if (mouseButton == Qt::MiddleButton) {
        qDebug()<<"中键";

    }else if (mouseButton == Qt::RightButton) {
        qDebug()<<"右键";
    }

}
void Label::mouseReleaseEvent(QMouseEvent *qme)
{
    qDebug()<<"释放按键";
}
void Label::mouseMoveEvent(QMouseEvent *qme)
{
    QString  location = QString(
                "<h1>x=%1,y=%2,Gx=%3,Gy=%4</h1>"
                )
            .arg(qme->x())
            .arg(qme->y())
            .arg(qme->globalX())
            .arg(qme->globalY());
    //    this->setText(location);
}
void Label::enterEvent(QEvent *qme)
{
    this->setText(QString("<h1>Mouse Enter</h1>"));
}
void Label::leaveEvent(QEvent *qme)
{
    this->setText(QString("<h1>Mouse Leave</h1>"));
}
